package client.automated;

import client.libmessenger.*;
import common.*;

public class AutomatedClient implements MSNListener 
{
	public LibMessenger libMessage = null;
	public boolean exiting = false;
	
	public static void main(String[] args) 
	{
		AutomatedClient bot = new AutomatedClient();
		
		bot.libMessage = new LibMessenger();
		bot.libMessage.listener = bot;
		
		if(!bot.libMessage.connect("127.0.0.1", "alex", "password"))
		{
			System.err.println("Could not connect to server\n");
			System.exit(-1);
		} // IF
		
		try
		{
			while(!bot.exiting) Thread.sleep(5);
		} // TRY
		catch(Exception e)
		{
			e.printStackTrace();
		} // CATCH
		
		bot.libMessage.disconnect();
	}
	
	public void onClientChangeStatus(String username, int status)
	{
	
	}
	public void onReceiveMessage(String username, String message)
	{
		System.out.println("Received message: "+message);
		
		libMessage.sendMessage("alex", username, "You say \""+message+"\", I say tomatoes!");
		
		if(message.toLowerCase().trim().equals("busy"))
			libMessage.changeStatus(Constants.ST_BUSY);
		
		if(message.toLowerCase().trim().equals("online"))
			libMessage.changeStatus(Constants.ST_ONLINE);
		
		if(message.toLowerCase().trim().equals("away"))
			libMessage.changeStatus(Constants.ST_AWAY);		
		
		if(message.toLowerCase().trim().equals("quit"))
			this.exiting = true;
	}	
	public void onFileTransferOffer(String username, String filename, String filesize)
	{
		
	}
	public void onFileSendStart(String username, String filename, int filesize)	
	{
		
	}
	public void onFileSendProgress(String destUserName, String filename, int fileSize, int bytesSent)
	{
		
	}
	public void onFileReceiveProgress(String sourceUserName, String filename, int fileSize, int bytesReceived)
	{
		
	}	
	// a client is starting a game with you
	public void onGameInitiation(String username, String gameName)
	{
		
	}
	// a client is sending you a move
	public void onGameMove(String username, String gameName, String move)
	{
		
	}
}
